package com.rules.admin.controller;

import com.rules.admin.utils.ResultUtils;
import com.rules.admin.entity.SysGroup;
import com.rules.admin.service.SysGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/group"})
public class SysGroupController {
   @Autowired
   private SysGroupService sysGroupService;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public List<SysGroup> getGroup(long userId) {
      return this.sysGroupService.get(userId);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public SysGroup addGroup(@RequestBody SysGroup sysGroup) {
      this.sysGroupService.save(sysGroup);
      return sysGroup;
   }

   @RequestMapping(
      value = {"/groups"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public List<SysGroup> getGroups() {
      return this.sysGroupService.list();
   }

   @RequestMapping(
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteGroup(SysGroup group) {
      this.sysGroupService.deleteByGroup(group);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/admin"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Boolean getAdmin() {
      return this.sysGroupService.getAdmin();
   }
}
